<?php
// +----------------------------------------------------------------------
// | HisiPHP框架[基于ThinkPHP5开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2018 http://www.HisiPHP.com
// +----------------------------------------------------------------------
// | HisiPHP承诺基础框架永久免费开源，您可用于学习和商用，但必须保留软件版权信息。
// +----------------------------------------------------------------------
// | Author: 橘子俊 <364666827@qq.com>，开发者QQ群：50304283
// +----------------------------------------------------------------------

namespace app\common\controller;

use think\Controller;
use think\Request;
use think\config;

/**
 * 接口公共控制器
 * @package app\common\controller
 */
class Api extends Controller
{
    protected $requestData;

    public function __construct()
    {
        parent::__construct();
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Headers:content-type');
        header('Access-Control-Request-Method:GET,POST');
        if (strtoupper($_SERVER['REQUEST_METHOD']) == 'OPTIONS') {
            exit;
        }
        $request = Request::instance();
        $this->requestData = $request->param();

        /*if(!isset($this->requestData['accessToken'])){
            $res = array(
                'status' => 0,
                'data'   => 'no accessToken',
                'code'   => 2,
            );
            echo json_encode($res);
            exit;
        }
        $accessToken = $this->getAccessToken($this->requestData);
        if($this->requestData['accessToken'] != $accessToken){
            $res = array(
                'status' => 0,
                'data'   => 'accessToken error',
                'code'   => 3,
            );
            echo json_encode($res);
            exit;
        }*/

    }

    private function getAccessToken($postData)
    {
        $tokenstr = "";
        foreach ($postData as $k => $v) {
            if ($k != 'accessToken') {
                $tokenstr .= $v;
            }
        }
        $pwdkey = Config::get('queue.api_key');
        $tokenstr .= $pwdkey;
        return sha1($tokenstr);
    }
}